program main
    implicit none
    integer :: head,tail,num,s1,s2
    data head,tail /100,200/
    logical,external :: judge
    do num = head,tail,2
        call resolve(num,s1,s2)!按顺序依次分解
        write(*,1) num,'=',s1,'+',s2
    end do
1   format(i3,a1,i3,a1,i3)
end program

subroutine resolve(num,s1,s2)
    ! 将num分解为两个质数s1和s2
    implicit none
    integer :: num,s1,s2
    logical,external :: judge
    s1 = 2
    s2 = num-2 
    do while( .not.(judge(s1) .and. judge(s2)) )
    !直到s1和s2均为质数时退出
        s1 = s1+1
        s2 = s2-1
    end do
end subroutine

logical function judge(n)
    !判断整数n是否是质数.是返回.true.
    integer :: n,i
    real :: r
    judge=.true.
    i=2
    if (n==2) then!特殊情况 
        goto 2
    end if
    r = sqrt(real(n))
    do while(i<=int(r))!寻找是否含有因数
        if(mod(n,i)==0) then
            judge = .false.
            goto 2
        end if
        i=i+1
    end do
2   continue
end function
